package org.project.server;

import java.io.IOException;
import java.net.URL;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;

import android.os.AsyncTask;
import android.util.Log;

public class AsyncSend extends AsyncTask<Void, Void, Object > {

	private HttpClient client_;
	private HttpPost post_;
	private AsyncSendCallback aSC_;
	private HttpResponse resp_;
	//private List<NameValuePair> areaList_;
	private Exception exception_ = null;
	
	public AsyncSend(HttpClient client, HttpPost post, AsyncSendCallback aSC){
		super();
		client_ = client;
		post_ = post;
		aSC_ = aSC;
	}
	
	@Override
	protected Object doInBackground(Void... params) {
		// TODO Auto-generated method stub
		Log.d("doInBackground", "begin");
	    try {
			resp_ = client_.execute(post_);
		} catch (ClientProtocolException e) {
			Log.e("catch ClientProtocol", "ERROR");
			e.printStackTrace();
		} catch (IOException e) {
			Log.e("IOException", "ERROR");
			e.printStackTrace();
		}
		return null;
	}
	
	protected void onPostExecute(Object result) {
		super.onPostExecute(result);
		Log.d("Async, onPost", "num:"+result);
		
		if(exception_ != null){
			aSC_.onError3(exception_);
		}
		else {
			aSC_.onResponse3( resp_);
		}
	}
}